<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 数组 扁平化  拉平、降维 、多维转一维 

        let arr =[11,22,[33,44,[55,66]]];   // [11,22,33,44,55,66]

        // console.log("es5 flat" ,arr.flat(Infinity) );

   //递归    
        function myFlat(arr){
           let xx=[]

            for(var v of arr){
                if( Array.isArray(v) ){
                    xx.push.apply(xx,myFlat(v))
                }else{
                    xx.push(v)
                  
                }
            }

           return xx;

        }

        
        console.log( myFlat(arr) );


// 正则匹配替换
        var str= JSON.stringify( arr );
        console.log(str); // [11,22,[33,44,[55,66]]]
        var str2= str.replace( /\[|\]/g,'' ) // 11,22,33,44,55,66
        str2='['+str2+']';  // [11,22,33,44,55,66]
        console.log(JSON.parse( str2 ));

    </script>
</body>
</html>